nition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<double> averageOfLevels(TreeNode* root) 
    {
        // 首先使用一个层序遍历 遍历出二叉树的每层的数组 之后对每个数组求平均值就可以
        vector<vector<double>> vv;
        vector<double> v;
        int levelsize = 1;
        TreeNode* cur = root;
        queue<TreeNode*> que;
        que.push(cur);    
        
        while(!que.empty())
        {
            if (levelsize) // levelsize != 0
            {
                levelsize--;
                cur = que.front();
                que.pop();
                if (cur->left)
                {
                    que.push(cur->left);
                }
                if (cur->right)
                {
                    que.push(cur->right);
                }
                v.push_back(cur->val);
            }
            else
            {
                levelsize = que.size();
                vv.push_back(v);
                v.clear();
            }
        }
        vv.push_back(v);
        vector<double> ans;
        for (auto e : vv)
        {
            int count = 0;
            double sum = 0;
            double answer = 0;
            for (auto x : e)
            {
                count++;
                sum += x;
            }
            answer = sum / count;
            ans.push_back(answer);
        }
        return ans;

